package com.game.frame;

import com.game.init.Main;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @作者: liwang
 * @时间: 2024/12/16
 * 首页
 * button   登陆按钮
 * button_1   注册按钮
 * button_2   排行榜按钮
 */
public class FirstPageFrame extends MyFrame{
    private JPanel contentPane;

    public FirstPageFrame(){
        super();


        this.setTitle("首页");

        contentPane = new JPanel();
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        JPanel panel = new JPanel();
        // 设置垂直排列
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        // 设置四周的边距  缩小可用空间
        panel.setBorder(BorderFactory.createEmptyBorder(50, 20, 50, 20));
        contentPane.add(panel, BorderLayout.CENTER);

        JButton button = new JButton("登录");
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Main.setStatus(1);
                System.out.println("点击登录");
                dispose();
            }

        });

        JButton button_1 = new JButton("注册");
        button_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("注册");
                Main.setStatus(2);
                dispose();
            }
        });

        JButton button_2 = new JButton("排行榜");
        button_2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("排行榜");
                Main.setStatus(3);
                dispose();
            }
        });

        panel.add(button);
        panel.add(Box.createVerticalStrut(20));
        panel.add(button_1);
        panel.add(Box.createVerticalStrut(20));
        panel.add(button_2);

//        contentPane.add(panel, BorderLayout.CENTER);

        this.setVisible(true); // 现实窗体
    }
}
